using Admin2025.Application.Contracts.Interface;
using Admin2025.Domain.Repositories;
using Admin2025.Infrastructure.Data;
using Admin2025.Infrastructure.Jwt;
using Admin2025.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Admin2025.Infrastructure;

public static class ServiceCollectionExtenstion
{
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
    {
        var connectionString = configuration.GetConnectionString("Mysql");

        services.AddDbContext<Admin2025DbContext>(x =>
        {
            x.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
        });

        services.AddScoped(typeof(IRespository<>), typeof(EfRepository<>));
        services.AddSingleton<IJwtService, JwtService>();

        return services;
    }
}